/*
 * Copyright (C) 2012 BARBOTIN Nicolas
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef GCROOMWIDGET_H
#define GCROOMWIDGET_H

#include <QWidget>
#include <QList>
#include <QImage>
#include <QPainter>
#include <QPaintEvent>
#include <QMouseEvent>
#include "GCProject.h"

typedef struct {
    int x;
    int y;
    int z;
} PosXYZ;

class GCRoomWidget : public QWidget
{
    Q_OBJECT
public:
    GCRoomWidget(QWidget *parent = 0);
    void setBackground(GCBackground newBg) { bg = newBg; hasBg = true; update(); }
    void removeBackground() { hasBg = false; update(); }
    void clearRoom() { objPos.clear(); sprites.clear(); removeBackground(); }
    void addObject(QImage sprite, int x, int y, int z);

public slots:
    void changeGridSize(int newSize) { gridSize = (unsigned short) newSize; update(); }
    void changeLayer(int newLayer) { layer = (unsigned short) newLayer; update(); }
    void setMode(bool mode) { isAdding = mode; }
    void setCurrentSprite(QImage spr) { currentSprite = spr; hasSpr = true; }
    void removeCurrentSprite() { currentSprite = QImage(); hasSpr = false; }

protected:
    void paintEvent(QPaintEvent*);
    void mouseReleaseEvent(QMouseEvent *e);

signals:
    void objectAdded(int x, int y, int z);
    void objectRemoved(int id);
    
private:
    unsigned short gridSize;
    unsigned short layer;
    bool isAdding;
    bool hasBg;
    bool hasSpr;
    QImage currentSprite;

    QList<QImage> sprites;
    QList<PosXYZ> objPos;
    GCBackground bg;

};

#endif // GCROOMWIDGET_H
